<?php

require_once ('Interface.php');

abstract class Joob_Plugins_Abstract implements Joob_Plugins_Interface {
	
	/* (non-PHPdoc)
	 * @see Joob_Plugins_Interface::onLoad()
	 */
	public function onLoad() {
		//Subclass should initialize variables here	
	}

	/**
	 * By default, this method trigger a method invocation (if exists) based on 
	 * the event name with the event data passed as a parameter
	 * E.g: An event named "RequestInit" will trigger the onRequestInit($eventData) method
	 * @see Joob_Plugins_Interface::onEvent()
	 */
	public function onEvent($event) {
		$methodName = 'on'.$event->getEventName();
		//avoid infinite recursion
		if ($methodName != "onEvent" && is_callable(array($this, $methodName)))	{
			return call_user_func_array(array($this, $methodName), array($event->getEventData()));
		}
		//return false if there is no such method
		return false;
	}

	/* (non-PHPdoc)
	 * @see Joob_Plugins_Interface::onUnload()
	 */
	public function onUnload() {
		//Subclass should finalize variables here
	}
}

?>